package cn.sccl.dirms.security.service.impl;

import cn.sccl.common.dao.BaseDAO;
import cn.sccl.common.service.impl.BaseManagerImpl;
import cn.sccl.dirms.security.dao.UnitDAO;
import cn.sccl.dirms.security.model.Unit;
import cn.sccl.dirms.security.service.UnitManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* 机构ID 的Manager实现类
* Created by P650RE3 on 2016-10-19.
*/
@Service
public class UnitManagerImpl extends BaseManagerImpl<Unit> implements UnitManager{

@Autowired
private UnitDAO unitDAO;

public UnitDAO getUnitDAO(){
return unitDAO;
}

@Override
public BaseDAO<Unit> getBaseDAO(){
return getUnitDAO();
}

    @Override
    public List<Unit> findUnit(){
        String sql = "select t.id,t.name from t_sec_unit t where t.delete_flag =0 order by t.name";
        return this.getDataBase().query4Model(sql,Unit.class);
    }

    @Override
    public Unit findUnitByStuUnNo(String unNo){
        String sql = "select u.* from t_dev_stu t，t_sec_unit u WHERE t.unit_id = u.id and t.delete_flag =0 and u.delete_flag =0 and t.un_No = '"+unNo+"'";
        List<Unit>  unitList = this.getDataBase().query4Model(sql,Unit.class);
        if(unitList != null && unitList.size() >0){
            return unitList.get(0);
        }else{
            return new Unit();
        }
    }
}